$(function(){
	$(".menubtns").click(function(){
		var index = $(this).data("index");
		$(".activemenubtn").removeClass("activemenubtn");
		$(this).addClass("activemenubtn");
		loadGrid(index);
	});
	$($(".menubtns")[0]).click();
	function loadGrid(index){
		$("#productListbox").html("");
		$(".loading").show();
		$.ajax({
			url : ctx + "/web/yjjj/productGrid",
			data : {
				type : index,
				page : 1,
				rows : 10000
			},
			success : function(data){
				$(".loading").hide();
				renderList(data);
			}
		});
	}
	
	function renderList(data){
		var rows = data.rows;
		for(var i = 0; i < rows.length; i++){
			var product = rows[i];
			var title = product.title;
			if(null != title && "" != title){
				if(title.length >= 32){
					title = title.substring(0,32)+"...";
				}
			}
			var oneBox = "<div class='boxlistout'>" +
							"<div class='boxlist'>" +
								"<div class='boxlist_1'><img class='boxlist_img todetails' data-myid='"+product.id+"' src='"+ctx+"/uploadfile/image/"+product.firstjjtp+"' alt=''/></div>"+
								"<div class='boxlist_2'><span class='todetails' data-myid='"+product.id+"'>"+title+"</span></div>"+
							"</div>" +
						"</div>";
			$("#productListbox").append(oneBox);
		}
		$(".todetails").bind("click",function(){
			var id = $(this).data("myid");
			window.location.href = ctx+"/web/yjjj/productDetail/"+id;
		});
		$(".boxlist_img").debigger({
			multiple:1.5,
			type : "2"
		});
	}
});